Page({
  data: {
    noReceiveAmount:null,  //未收
    receiveAmount:null,   //已收
    totalAmount:null   //总额

  },
  onLoad() {
    
    let token = my.getStorageSync({ key: 'token' }).data;

    if(token == null){
      my.confirm({
      title: '温馨提示',
      content: '当前还未登录：是否需要登录？',
      confirmButtonText: '马上登录',
      cancelButtonText: '暂不需要',
      success: (result) => {
        if(result.confirm){
            //登录
            my.redirectTo({
             url: '/pages/common/login/login'
            })
        }else{
          //暂不登录
           my.switchTab({
             url: '/pages/user/user'
            })
        }
        },
      });
      return false;
    }

    let that = this;
    my.showLoading({
      content: '加载中...'
    });
    //请求数据
    my.request({
    url: 'https://tiyi.site/seaHorse/draw/statis/orderAmounts',
    method: 'POST',
    headers: 
    {
     'content-type': 'application/json',
     'token':token
    },
    data: {},
    dataType: 'json',
    success: function(res) {
      if(res.data.code == 0){
        that.setData({
          noReceiveAmount:res.data.noReceiveAmount,
          receiveAmount:res.data.receiveAmount,
          totalAmount:res.data.totalAmount
        })
      }else if(res.data.code == 401){
          //去登录
          my.redirectTo({
            url: '/pages/common/login/login'
          }) 
      }
    },
    fail: function(res) {
      my.alert({content: res});
    },
    complete: function(res) {
      my.hideLoading();
    }
    });
  },
  returnIndex() {
    my.redirectTo ({ url: '/pages/receipt/receipt' });
  },
});